package com.zlm.test;

import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Author: Harbour
 * Date: 2021-05-08 14:10
 * Desc: 流式wc
 */
public class StreamWordCount {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        // 用 parameter tool 获取配置参数
        ParameterTool params = ParameterTool.fromArgs(args);
        String host = "hadoop201";
        int port = 7777;

        DataStreamSource<String> streamSource = env.socketTextStream(host, port);
//        DataStream<String> streamSource = env.readTextFile("D:\\JavaProject\\real-time-data-warehouse\\learning\\src\\main\\resources\\wc.txt");

        streamSource.flatMap(new WordCount.MyFlatMapper()).keyBy(0).sum(1).print();

        env.execute();
        env.wait();
    }
}
